import json
import urllib.request
import urllib.parse


url="https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1719576935880_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true"
headers = {
    "Cookie": "t=84e37c19683bd933391b6248481aaa59; cookie2=1af62d1ec3025074c4d41be6603947c5; v=0; _tb_token_=533603f465570; cna=n+sDH0X1WmcCAQAAAAA3i6KP; xlly_s=1; tb_city=110100; tb_cityName='sbG+qQ=='; isg=BJaWOSwq7BxG5ti5zc8C2kZx50yYN9pxMujHnwD9QHl2wzZdaMeSgbm5W18v69KJ"
    ,"Referer": "https://dianying.taobao.com/?spm=a1z21.3046609.city.1.1990112aarqSUR&city=110100",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
}

# 请求
request =urllib.request.Request(url=url, headers=headers)
# 模拟浏览器向服务器发送请求
response = urllib.request.urlopen(request)
# 响应
content = response.read().decode("utf-8")
# 以（做切割，分为两个元素，保留下标为1元素 以）做切割   保留下标为0的元素
content =content.split("(")[1].split(")")[0]
with open("19jsonpath解析淘票票.json","w",encoding="utf-8") as f:
    f.write(content)

import jsonpath

obj=json.load(open("19jsonpath解析淘票票.json","r",encoding="utf-8"))
city_list=jsonpath.jsonpath(obj,'$..regionName')

print(city_list)
